
package cn.le;

import cn.le.bean.dto.MsgPointDTO;
import cn.le.bean.enums.EnumMsgCode;
import cn.le.bean.util.RestfullClient;
import cn.le.bean.vo.NettyMsg;
import cn.le.netty.cient.NettyClient;
import cn.le.util.InputUtil;
import com.alibaba.fastjson.JSONObject;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;

import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@SpringBootApplication
public class BClientApplication {

    public static void main(String[] args) throws IOException {
        SpringApplication.run(BClientApplication.class,args);
        String ip = "192.168.0.86";
        //登录im-服务器
        String url= "http://127.0.0.1:8081/im/imUser/login";
        Map<String,Object> param =  new HashMap<>();
        String name = "b";
        param.put("pwd",name);
        param.put("name",name);
        RestfullClient.okPost(url,param);
        //登录netty服务器
        NettyClient.login(ip,1111,2);
        System.out.println("---------欢迎使用im通信,下面请开始你的表演---------");
        boolean flag = true;
        while (flag){
            String content = InputUtil.getString(name+":").trim();
            if ("bye".equalsIgnoreCase(content)){
                flag = false;
            }
            NettyMsg msg = new NettyMsg(UUID.randomUUID().toString(),2,1,content, EnumMsgCode.point_send.getCode());
            NettyClient.sendPoint(msg);
            MsgPointDTO dto = new MsgPointDTO();
            dto.setId(UUID.randomUUID().toString());
            dto.setFid(2);
            dto.setTid(1);
            dto.setContent(content);
            //RestfullClient.okPost("http://127.0.0.1:8081/im/imMsg/sendPoint", JSONObject.toJSONString(dto));
        }
    }
}

